home *** CD-ROM | disk | FTP | other *** search
/ PC Open 107 / PC Open 107 CD 1.bin / CD1 / INTERNET / COPIA SITI / Getleft / getleft-setup-notcl.exe / {app} / scripts / FrameLabel.tcl < prev    next >
Encoding:
Text File  |  2004-02-21  |  2.2 KB  |  59 lines

  1. ###############################################################################
  2. ###############################################################################
  3. ##                          FrameLabel
  4. ###############################################################################
  5. ###############################################################################
  6. ## Creates a frame with a label in the top-left of it.
  7. ###############################################################################
  8. ###############################################################################
  9. ## (c) 2000 AndrΘs Garcφa Garcφa. fandom@retemail.es
  10. ## You may distribute the contents of this file under the terms of the LGPL v2
  11. ###############################################################################
  12. ###############################################################################
  13.  
  14. namespace eval fl {
  15.  
  16. ###############################################################################
  17. # FrameLabel
  18. #    Creates the frame with the label.
  19. #
  20. # Parameters
  21. #    framePath: path to the frame.
  22. #    args: Arguments to be passed to the label and the frame, actually the
  23. #          label only accepts 'text' or 'textvariable', the rest go to 
  24. #          the frame.
  25. ###############################################################################
  26. proc FrameLabel {framePath args} {
  27.  
  28.     frame $framePath
  29.  
  30.     regexp {(^\.[^\.]+)(.*)} $framePath nada toplevelPath parentFrame
  31.     regsub -all {\.} $parentFrame {} parentFrame
  32.  
  33.     set labelPath $toplevelPath.$parentFrame
  34.     set frameArgs ""
  35.     foreach {option value} $args {
  36.         switch -exact -- $option {
  37.             -text {
  38.                 set frameLabel [label $labelPath -text $value]
  39.             }
  40.             -textvariable {
  41.                 set frameLabel [label $labelPath -textvariable $value]
  42.             }
  43.             default {
  44.                 lappend frameArgs $option $value
  45.             }
  46.         }
  47.     }
  48.     eval $framePath configure $frameArgs
  49.  
  50.     set ascent [font metrics [$labelPath cget -font] -ascent]
  51.     place $frameLabel -in $framePath -x [expr {$ascent/2}] -y -$ascent            
  52.  
  53.     bind $framePath <Destroy> "destroy $labelPath ; break"
  54.  
  55.     return $framePath
  56. }
  57.  
  58. }
  59.